package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.CustomerDao;
import com.atguigu.jxc.entity.Customer;
import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.service.CustomerService;
import com.atguigu.jxc.util.PageResult;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author ONIE
 * @create 2021/11/25 2:28 下午
 */
@Service
public class CustomerServiceImpl implements CustomerService {
	@Autowired
	private CustomerDao customerDao;

	@Override
	public PageResult coustomerList(Integer page, Integer rows, String coustomerName) {
		PageHelper.startPage(page,rows);
		Page<Customer> customerPage = customerDao.customerList(coustomerName);
		return new PageResult(customerPage.getTotal(),customerPage.getResult());
	}

	@Override
	public void saveByCoustomerId(Integer customerId, Customer customer) {
		if (customerId == null){
			customerDao.saveCustomer(customer);
		}else {
			customerDao.updateById(customerId,customer);
		}
	}

	@Override
	public void deleteByIds(String ids) {
		String[] split = ids.split(",");
		customerDao.deleteByIds(split);
	}
}
